#ifndef COMMONLIST_H
#define COMMONLIST_H

#include <list>
#include "Common/Macro.h"

template <typename TYPE>
class CommonList : private std::list<TYPE>
{
private:
	typedef std::list<TYPE> stlType;

public:
	typedef stlType::iterator iterator;
	typedef stlType::const_iterator const_iterator;
	typedef stlType::reverse_iterator reverse_iterator;
	typedef stlType::const_reverse_iterator const_reverse_iterator;

public:
							CommonList		()									{}
							~CommonList		()									{}

	uint					GetLength	()									{ return stlType::size(); }
	bool					IsEmpty		()									{ return stlType::empty(); }

	void					AddLast		(TYPE& aRef)						{ stlType::push_back(aRef); }
	void					Add			(const iterator& aIt, TYPE& aRef)	{ stlType::insert(aIt, aRef); }
	void					AddFirst	(TYPE& aRef)						{ stlType::push_front(aRef); }
	void					AddSort		(TYPE& aRef)
	{
		iterator i = begin();
		while ( i < end() && i < aRef) {++i; }
		Add(i, aRef);
	}


	void					clear		()									{ std::list<TYPE>::clear(); }

	TYPE&					getFirst	()									{ return stlType::front(); }
	const TYPE&				getFirst	() const							{ return stlType::front(); }
	TYPE&					getLast		()									{ return stlType::back(); }
	const TYPE&				getLast		() const							{ return stlType::back(); }

	void					removeFirst	()									{ stlType::pop_front(); }
	void					removeLast	()									{ stlType::pop_back(); }
	void					remove		( const TYPE& _elmt )				{ stlType::remove( _elmt ); }
	void					remove		( const iterator& _it )				{ stlType::erase( _it ); }

	iterator				begin		()									{ return stlType::begin(); }
	const_iterator			begin		() const							{ return stlType::begin(); }

	iterator				end			()									{ return stlType::end(); }
	const_iterator			end			() const							{ return stlType::end(); }

	reverse_iterator		rbegin		()									{ return stlType::rbegin(); }
	const_reverse_iterator	rbegin		() const							{ return stlType::rbegin(); }

	reverse_iterator		rend		()									{ return stlType::rend(); }
	const_reverse_iterator	rend		() const							{ return stlType::rend(); }

	void					sort		( bool (*_fn)( TYPE, TYPE ) )		{ return stlType::sort( _fn ); }
};

#endif